<template>
  <div class="itembox">
    <i class='iconfont iconback01 back' @click="toPre"></i>
    <h1 class="bluetit titfont">{{title}}</h1>
    <div class = "itembtns">
      <!-- <router-link to="/print"  -->
      <div
          class="lawbtn"
          v-for="item of lawlist"
          :key="item.data_id"
          @click="serchres(item.data_id)"
      >
        {{item.title}}
      </div>
      <!-- <div class="lawbtn nomargin">按优惠政策查询</div> -->
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default{
  name:'SerchItem',
  data () {
    return {
      title:'',
      lawlist:[]
    }
  },
  methods:{
    toPre(){
      this.$router.go(-1);
    },
    async getLawInfo (){
      let param_type = this.$route.params.type
      let url = 'law/params?param_type='+param_type
      if(param_type=="year"){
        console.log('time')
        this.title = '按时间查询'
        let myDate = new Date()
        let this_year = myDate.getFullYear()
        let arr = []

        for(let i = this.$store.state.year_start; i<=this_year; i++){
          arr.push({
            data_id:i,
            title:i+'年'
          })
        }
        this.lawlist = arr
      }else{
        axios.get(url,{
          param_type
        }).then((res)=>{
          res = res.data
          console.log(res)
          if (res.status==200) {
            let type = this.$route.params.type
            if(type = 'category'){
              this.title = '分税种查询'
            }else if(type = 'vocation'){
              this.title = '分行业查询'
            }else if(type = 'special'){
              this.title = '分专题查询'
            }else{
              this.title = '税收优惠政策'
            }
            this.lawlist = res.msg
          }
        })
      }
    },
    serchres(id){
      let param_type = this.$route.params.type
      this.$router.push({name:'Print',query:{param_type,id}})
    }
  },
  mounted () {
    this.getLawInfo()
  }
}
</script>

<style>
.itembox{
  padding:50px;
}
.titfont{
  height: 15px;
  line-height: 15px;
  font-size: 18px;
  margin-bottom: 30px;
  font-weight: 300 !important;
}
.itembtns{
  display: flex;
  flex-direction:row;
  flex-wrap: wrap;
  /*justify-content:space-between;*/
}
.lawbtn{
  display: inline-block;
  font-size: 16px;
  color:#2254E7;
  border:1px solid #2254E7;
  width: 170px;
  height: 48px;
  line-height: 48px;
  text-align: center;
  border-radius: 6px;
  margin-right: 5px;
  margin-bottom: 10px;
  font-weight: 300;
  cursor:pointer;
}
.nomargin{
  margin-right: 0;
}
.back{
  font-size: 30px;
  color:#999;
  position: absolute;
  top:150px;
  right:40px;
}
.back:hover{
  color:#2254E7;
}

</style>